---
id: "include"
keywords: ["include", "module"]
name: "include"
summary: "This is the `include` keyword."
category: "languageconstructs"
---

The `include` keyword statically "spreads" all public values, types, modules, etc. of a given module into the current module's scope. This is sometimes useful to create supersets / mixins of different modules.

> Note that `include` may make your code more complex and harder to understand when abused. Think twice before using it.

### Include module example

<CodeTab labels={["ReScript", "JS Output"]}>

```res
module Message = {
  let greeting = "Hello"
}

module Greeter = {
  include Message
  let greet = name => greeting ++ " " ++ name
}
```

```js
var greeting = "Hello";

var Message = {
  greeting: greeting,
};

function greet(name) {
  return "Hello " + name;
}

var Greeter = {
  greeting: greeting,
  greet: greet,
};
```

</CodeTab>

Similarly, module signatures can also be extended by other module signatures.

### Include signature example

<CodeTab labels={["ReScript", "JS Output"]}>

```res
module type Message = {
  let greeting: string
}

module type Greeter = {
  include Message
  let greet: string => string
}
```

```js
// No output
```

</CodeTab>

Lastly, you can also extract module types from existing modules using `module type of`.

### Include "module type of" example

<CodeTab labels={["ReScript", "JS Output"]}>

```res
module Message = {
  let greeting = "Hello"
}

module type Greeter = {
  // Includes the type definitions of Message
  include module type of Message
  let greet: string => string
}
```

```js
var Message = {
  greeting: "Hello",
};
```

</CodeTab>

### References

- [Extending modules](../docs/manual/module.mdx#extending-modules)
- [Extending module signatures](../docs/manual/module.mdx#extending-module-signatures)
